import { request } from "@/utils/service"
import type * as TaskJob from "./types/taskJob"
import * as Common from "@/api/common/types/common"

/** 修改基本信息 */
export function updateTaskJobBaseDataApi(data: TaskJob.TaskJobData) {
  return request({
    url: "taskJob/updateBase",
    method: "post",
    data: data
  })
}

/** 查 */
export function getTaskJobDataApi(data: TaskJob.TaskJobDataRequestData) {
  return request<TaskJob.TaskJobDataResponseData>({
    url: "taskJob/list",
    method: "post",
    data: data
  })
}

/** 运行一次 */
export function runOnceApi(id: number) {
  return request({
    url: `taskJob/runOnce/${id}`,
    method: "get"
  })
}

/** 暂停 */
export function pauseApi(id: number) {
  return request({
    url: `taskJob/pause/${id}`,
    method: "get"
  })
}

/** 恢复运行 */
export function resumeApi(id: number) {
  return request({
    url: `taskJob/resume/${id}`,
    method: "get"
  })
}

/** 注册任务 */
export function registerApi(id: number) {
  return request({
    url: `taskJob/register/${id}`,
    method: "get"
  })
}

/** 移除任务 */
export function removeApi(id: number) {
  return request({
    url: `taskJob/remove/${id}`,
    method: "get"
  })
}

/** 修改运行频率 */
export function modifyCronApi(id: number, cron: string) {
  return request({
    url: `taskJob/modifyCron/${id}`,
    method: "post",
    params: {
      cron
    }
  })
}

/** 定时任务下拉框 */
export function getTaskJobOptionsApi() {
  return request<Common.SelectResponseData>({
    url: "/taskJob/select",
    method: "get"
  })
}

/* *********************************************************/

/** 查询日志 */
export function getTaskJobLogDataApi(data: TaskJob.TaskJobLogDataRequestData) {
  return request<TaskJob.TaskJobLogDataResponseData>({
    url: "taskJobLog/list",
    method: "post",
    data: data
  })
}

// 获取某个日志的详情列表
export function getTaskJobLogDetailApi(id: number) {
  return request<ApiResponseData<TaskJob.TaskJobLogDetailData[]>>({
    url: `taskJobLog/detail/${id}`,
    method: "get"
  })
}
